package com.sinosoft.perfect.system._user.dataFormat;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.sinosoft.perfect.common.xmlService.XmlInfoBean;
import com.sinosoft.perfect.common.xmlService.XmlProducerDom4j;
import com.sinosoft.perfect.system._.po.TUser;
import com.sinosoft.perfect.system._user.formBean.UserForm;
import com.sinosoft.perfect.system._user.vo.UserStaticVO;

public class UserGridDataFormat_DHX implements IUserGridDataFormat {

	@Override
	public String dataFormatUserGrid(List<TUser> userList) {
		List<XmlInfoBean> infos = new ArrayList<XmlInfoBean>();
		XmlInfoBean info = new XmlInfoBean();
		info.setLevel("0");
		info.setMyid("0");
		info.setName("rows");
		infos.add(info);
		if (userList != null && userList.size() > 0) {
			for (int i = 0; i < userList.size(); i++) {
				TUser u = userList.get(i);

				XmlInfoBean row = new XmlInfoBean();
				row.setMyid(u.getUserMainId());
				row.setName("row");
				row.setParentId("0");
				Map<String, String> properties = new HashMap<String, String>();
				properties.put("id", u.getUserMainId());
				row.setProperties(properties);
				infos.add(row);

				XmlInfoBean cell1 = new XmlInfoBean();
				cell1.setName("cell");
				cell1.setParentId(u.getUserMainId());
				cell1.setContent(i + 1 + "");
				infos.add(cell1);

				XmlInfoBean cell2 = new XmlInfoBean();
				cell2.setName("cell");
				cell2.setParentId(u.getUserMainId());
				cell2.setContent(u.getLoginCode());
				infos.add(cell2);

				XmlInfoBean cell3 = new XmlInfoBean();
				cell3.setName("cell");
				cell3.setParentId(u.getUserMainId());
				cell3.setContent(u.getLoginName());
				infos.add(cell3);

				XmlInfoBean cell4 = new XmlInfoBean();
				cell4.setName("cell");
				cell4.setParentId(u.getUserMainId());
				cell4.setContent(u.getNote());
				infos.add(cell4);
			}
		}
		return XmlProducerDom4j.generateXMLString(infos);
	}

	@Override
	public String dataFormatUserStaticGrid(List<UserStaticVO> userStaticVOList) {
		List<XmlInfoBean> infos = new ArrayList<XmlInfoBean>();
		XmlInfoBean info = new XmlInfoBean();
		info.setLevel("0");
		info.setMyid("0");
		info.setName("rows");
		infos.add(info);
		if (userStaticVOList != null && userStaticVOList.size() > 0) {
			for (int i = 0; i < userStaticVOList.size(); i++) {
				UserStaticVO userStaticVO = userStaticVOList.get(i);

				XmlInfoBean row = new XmlInfoBean();
				row.setMyid(userStaticVO.getUserId());
				row.setName("row");
				row.setParentId("0");
				Map<String, String> properties = new HashMap<String, String>();
				properties.put("id", userStaticVO.getUserId());
				row.setProperties(properties);
				infos.add(row);

				XmlInfoBean cell1 = new XmlInfoBean();
				cell1.setName("cell");
				cell1.setParentId(userStaticVO.getUserId());
				cell1.setContent(i + 1 + "");
				infos.add(cell1);

				XmlInfoBean cell2 = new XmlInfoBean();
				cell2.setName("cell");
				cell2.setParentId(userStaticVO.getUserId());
				cell2.setContent(userStaticVO.getLoginName());
				infos.add(cell2);

				XmlInfoBean cell3 = new XmlInfoBean();
				cell3.setName("cell");
				cell3.setParentId(userStaticVO.getUserId());
				cell3.setContent(userStaticVO.getLoginCode());
				infos.add(cell3);

				XmlInfoBean cell4 = new XmlInfoBean();
				cell4.setName("cell");
				cell4.setParentId(userStaticVO.getUserId());
				cell4.setContent(userStaticVO.getAllLoginCount());
				infos.add(cell4);

				XmlInfoBean cell5 = new XmlInfoBean();
				cell5.setName("cell");
				cell5.setParentId(userStaticVO.getUserId());
				SimpleDateFormat sdf = new SimpleDateFormat();
				cell5.setContent(sdf.format(userStaticVO.getLastLogintime()));
				infos.add(cell5);
			}
		}
		return XmlProducerDom4j.generateXMLString(infos);
	}

	@Override
	public String dataFormatUserDetachGrid(List<TUser> userList) {
		List<XmlInfoBean> infos = new ArrayList<XmlInfoBean>();
		XmlInfoBean info = new XmlInfoBean();
		info.setLevel("0");
		info.setMyid("0");
		info.setName("rows");
		infos.add(info);
		if (userList != null && userList.size() > 0) {
			for (int i = 0; i < userList.size(); i++) {
				TUser user = userList.get(i);

				XmlInfoBean row = new XmlInfoBean();
				row.setMyid(user.getUserMainId());
				row.setName("row");
				row.setParentId("0");
				Map<String, String> properties = new HashMap<String, String>();
				properties.put("id", user.getUserMainId());
				row.setProperties(properties);
				infos.add(row);

				XmlInfoBean cell1 = new XmlInfoBean();
				cell1.setName("cell");
				cell1.setParentId(user.getUserMainId());
				cell1.setContent(i + 1 + "");
				infos.add(cell1);

				XmlInfoBean cell2 = new XmlInfoBean();
				cell2.setName("cell");
				cell2.setParentId(user.getUserMainId());
				cell2.setContent(user.getLoginCode());
				infos.add(cell2);

				XmlInfoBean cell3 = new XmlInfoBean();
				cell3.setName("cell");
				cell3.setParentId(user.getUserMainId());
				cell3.setContent(user.getLoginName());
				infos.add(cell3);

				XmlInfoBean cell4 = new XmlInfoBean();
				cell4.setName("cell");
				cell4.setParentId(user.getUserMainId());
				cell4.setContent(user.getNote());
				infos.add(cell4);
			}
		}
		return XmlProducerDom4j.generateXMLString(infos);
	}

	@Override
	public String dataFormatUserFromUnitGrid(List<UserForm> userFormList) {
		List<XmlInfoBean> infos = new ArrayList<XmlInfoBean>();
		XmlInfoBean info = new XmlInfoBean();
		info.setLevel("0");
		info.setMyid("0");
		info.setName("rows");
		infos.add(info);
		if (userFormList != null && userFormList.size() > 0) {
			for (int i = 0; i < userFormList.size(); i++) {
				UserForm u = userFormList.get(i);

				XmlInfoBean row = new XmlInfoBean();
				row.setMyid(u.getUserMainId());
				row.setName("row");
				row.setParentId("0");
				Map<String, String> properties = new HashMap<String, String>();
				properties.put("id", u.getUserMainId());
				row.setProperties(properties);
				infos.add(row);

				XmlInfoBean cell1 = new XmlInfoBean();
				cell1.setName("cell");
				cell1.setParentId(u.getUserMainId());
				cell1.setContent(i + 1 + "");
				infos.add(cell1);

				XmlInfoBean cell2 = new XmlInfoBean();
				cell2.setName("cell");
				cell2.setParentId(u.getUserMainId());
				cell2.setContent(u.getLoginName());
				infos.add(cell2);

				XmlInfoBean cell3 = new XmlInfoBean();
				cell3.setName("cell");
				cell3.setParentId(u.getUserMainId());
				cell3.setContent(u.getLoginCode());
				infos.add(cell3);

				XmlInfoBean cell4 = new XmlInfoBean();
				cell4.setName("cell");
				cell4.setParentId(u.getUserMainId());
				cell4.setContent(u.getNote());
				infos.add(cell4);
			}
		}
		return XmlProducerDom4j.generateXMLString(infos);
	}

	@Override
	public String dataFormatUserFromRoleBusinessGrid(List<UserForm> userFormList) {
		List<XmlInfoBean> infos = new ArrayList<XmlInfoBean>();
		XmlInfoBean info = new XmlInfoBean();
		info.setLevel("0");
		info.setMyid("0");
		info.setName("rows");
		infos.add(info);
		if (userFormList != null && userFormList.size() > 0) {
			for (int i = 0; i < userFormList.size(); i++) {
				UserForm uForm = userFormList.get(i);

				XmlInfoBean row = new XmlInfoBean();
				row.setMyid(uForm.getUserMainId());
				row.setName("row");
				row.setParentId("0");
				Map<String, String> properties = new HashMap<String, String>();
				properties.put("id", uForm.getUserMainId());
				row.setProperties(properties);
				infos.add(row);

				XmlInfoBean cell1 = new XmlInfoBean();
				cell1.setName("cell");
				cell1.setParentId(uForm.getUserMainId());
				cell1.setContent(i + 1 + "");
				infos.add(cell1);

				XmlInfoBean cell2 = new XmlInfoBean();
				cell2.setName("cell");
				cell2.setParentId(uForm.getUserMainId());
				cell2.setContent(uForm.getLoginName());
				infos.add(cell2);

				XmlInfoBean cell3 = new XmlInfoBean();
				cell3.setName("cell");
				cell3.setParentId(uForm.getUserMainId());
				cell3.setContent(uForm.getLoginCode());
				infos.add(cell3);

				XmlInfoBean cell4 = new XmlInfoBean();
				cell4.setName("cell");
				cell4.setParentId(uForm.getUserMainId());
				cell4.setContent(uForm.getNote());
				infos.add(cell4);
			}
		}
		return XmlProducerDom4j.generateXMLString(infos);
	}

	@Override
	public String dataFormatUserFromRoleSystemGrid(List<UserForm> userForms) {
		List<XmlInfoBean> infos = new ArrayList<XmlInfoBean>();
		XmlInfoBean info = new XmlInfoBean();
		info.setLevel("0");
		info.setMyid("0");
		info.setName("rows");
		infos.add(info);
		if (userForms != null && userForms.size() > 0) {
			for (int i = 0; i < userForms.size(); i++) {
				UserForm uForm = userForms.get(i);

				XmlInfoBean row = new XmlInfoBean();
				row.setMyid(uForm.getUserMainId());
				row.setName("row");
				row.setParentId("0");
				Map<String, String> properties = new HashMap<String, String>();
				properties.put("id", uForm.getUserMainId());
				row.setProperties(properties);
				infos.add(row);

				XmlInfoBean cell1 = new XmlInfoBean();
				cell1.setName("cell");
				cell1.setParentId(uForm.getUserMainId());
				cell1.setContent(i + 1 + "");
				infos.add(cell1);

				XmlInfoBean cell2 = new XmlInfoBean();
				cell2.setName("cell");
				cell2.setParentId(uForm.getUserMainId());
				cell2.setContent(uForm.getLoginName());
				infos.add(cell2);

				XmlInfoBean cell3 = new XmlInfoBean();
				cell3.setName("cell");
				cell3.setParentId(uForm.getUserMainId());
				cell3.setContent(uForm.getLoginCode());
				infos.add(cell3);

				XmlInfoBean cell4 = new XmlInfoBean();
				cell4.setName("cell");
				cell4.setParentId(uForm.getUserMainId());
				cell4.setContent(uForm.getNote());
				infos.add(cell4);
			}
		}
		return XmlProducerDom4j.generateXMLString(infos);
	}

}
